#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
using namespace std;

void handler(int signo)
{
    cout << "get a signo : " << signo << endl;

    //回收子进程
    waitpid(-1, nullptr, 0); //阻塞等待
}

int main()
{
    signal(SIGCHLD, handler);
    pid_t id = fork();
    if(id == 0)
    {
        //child
        cout << "child is running" << endl;
        sleep(5);
        exit(10);
    }
    while(1)
    {
        sleep(1); //父进程一直在进行某种服务
    }
    return 0;
}
